/* 
 * AC
 * DP
 * gcc poj_3616.c -Wall
 **/
#include <stdio.h>
#include <stdlib.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int M[1000][4];

int comp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}
int main(int argc, char **argv)
{
	int n, m, r;
	char buffer[4096];
	int i, j, maxx = 0;

	fgets(buffer, sizeof buffer, stdin);
	sscanf(buffer, "%d %d %d", &n, &m, &r);
	for (i = 0; i < m; i++) {
		fgets(buffer, sizeof buffer, stdin);
		sscanf(buffer, "%d %d %d", &M[i][0], &M[i][1], &M[i][2]);
		M[i][3] = M[i][2];
	}

	qsort(M, m, sizeof M[0], comp);
	for (i = 0; i < m; i++) {
		for (j = 0; j <= i; j++) {
			if (M[i][0] - M[j][1] >= r) {
				M[i][3] = max(M[i][3], M[j][3] + M[i][2]);
			}
		}
	}
	for (i = 0; i < m; i++)
		maxx = max(maxx, M[i][3]);
	printf("%d\n", maxx);
	return 0;
}
